<template>
  <div>
      <div id="main" style="width: 80%;height:400px;"></div>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
// import echarts from "echarts"
export default {
  components: {},
  computed: {
    ...mapGetters({
      list:"cate/list"
    }),
  },
  methods: {
    ...mapActions({
      reqList:"cate/reqList"
    }),
  },
  mounted() {
    //请求list
    this.reqList();
  },
  watch:{
    list:{
      handler(){
        if(this.list.length>0){
          // 基于准备好的dom，初始化echarts实例
        var myChart = require("echarts").init(document.getElementById('main'));

        // 指定图表的配置项和数据
        var option = {
          color: ["#696969", "#2f4554", "#61a0a8"],
            title: {
                text: '商品分类数据'
            },
            tooltip: {},
            legend: {
                data:['子类数据']
            },
            xAxis: {
                data: this.list.map(item=>item.catename)
            },
            yAxis: {},
            //数据
            series: [{
                name: '子类数量',
                type: 'line',
                data: this.list.map(item=>item.children?item.children.length:0)
            }]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
        }
      },
      deep:true,
    }
  },
  props: [],
  data() {
    return {};
  },
};
</script>
<style lang="less" scoped>
</style>